Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tapioca Add-on] Trigger DSL generation upon file changes #2031

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

KaanOzkan
Copy link
Contributor

@KaanOzkan KaanOzkan commented Oct 3, 2024

Motivation

Merge part of tapioca add-on logic

Implementation

  • Bump ruby-lsp and ruby-lsp-rails
  • Use new API in ruby-lsp
  • Implement workspace_did_change_watched_files method that uses the Ruby LSP index to find potentially modified constants in a file and sends them to the Rails app

Tests

We'll add tests when we can test rails client

constants = changes.filter_map do |change|
path = change[:uri].gsub("file://", "")

entries = T.must(@index).entries_for(path, RubyIndexer::Entry::Class, RubyIndexer::Entry::Module)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using grep, getting subclasses and then filtering them out feels weird to me. Wdyt of an API like this where you have a rest arg and use == instead? Or making the second argument optional and returning all entries by default?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use the parent class to filter both at the same time.

Suggested change
entries = T.must(@index).entries_for(path, RubyIndexer::Entry::Class, RubyIndexer::Entry::Module)
entries = T.must(@index).entries_for(path, RubyIndexer::Entry::Namespace)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't only use the parent class because it includes singleton classes. So I'm trying to avoid this filtering with a different API in Ruby LSP main...andyw8/tapioca-lsp#diff-8243d0258619c7955b4277251f121d4b6788da80bcae39fe5130f27019d143bbR64

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for our use case being able to omit the types and do our own filtering in tapioca makes sense. Will you accept that change in Ruby LSP?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, we created that API for the Tapioca add-on, so we can change it to whatever makes sense.

@KaanOzkan KaanOzkan marked this pull request as ready for review October 3, 2024 22:19
@KaanOzkan KaanOzkan requested a review from a team as a code owner October 3, 2024 22:19
@KaanOzkan KaanOzkan requested review from Morriar, amomchilov, andyw8, alexcrocha and vinistock and removed request for a team, Morriar and amomchilov October 3, 2024 22:19
lib/ruby_lsp/tapioca/addon.rb Show resolved Hide resolved
constants = changes.filter_map do |change|
path = change[:uri].gsub("file://", "")

entries = T.must(@index).entries_for(path, RubyIndexer::Entry::Class, RubyIndexer::Entry::Module)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use the parent class to filter both at the same time.

Suggested change
entries = T.must(@index).entries_for(path, RubyIndexer::Entry::Class, RubyIndexer::Entry::Module)
entries = T.must(@index).entries_for(path, RubyIndexer::Entry::Namespace)

lib/ruby_lsp/tapioca/addon.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/tapioca/addon.rb Show resolved Hide resolved
lib/ruby_lsp/tapioca/addon.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/tapioca/addon.rb Outdated Show resolved Hide resolved
@KaanOzkan KaanOzkan force-pushed the ko/addon-watched-files branch 3 times, most recently from dfa196d to 479d175 Compare October 4, 2024 17:22
@KaanOzkan KaanOzkan added the enhancement New feature or request label Oct 7, 2024
@KaanOzkan KaanOzkan merged commit b6aac6a into tapioca-addon-feature-branch Oct 7, 2024
28 of 29 checks passed
@KaanOzkan KaanOzkan deleted the ko/addon-watched-files branch October 7, 2024 15:06
@vinistock
Copy link
Member

We need to also update the Addon.get call to constraint the version to one that defines the new APIs:

# We need to change this to >= 0.3.18
addon = T.cast(::RubyLsp::Addon.get("Ruby LSP Rails", ">= 0.3.17", "< 0.4"), ::RubyLsp::Rails::Addon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants